package com.ce.server.util;

import com.ce.server.common.Today;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

import static cn.hutool.core.date.LocalDateTimeUtil.*;

/**
 * @Author hyx
 * @Date 2021/11/19 10:03
 * @Version 1.0
 */
public class TimeUtil {

    /**
     * 检测输入的时间是否是当天
     * @param time 待检测的时间
     * @return
     */
    public static boolean isToday(LocalDateTime time) {
        if (time == null) return false;
        LocalDateTime now = parse(LocalDateTime.now().toString());
        LocalDateTime beginOfDay = beginOfDay(now);
        LocalDateTime endOfDay = endOfDay(now);
        return between(beginOfDay, time).toMillis() >= 0 && between(time, endOfDay).toMillis() >= 0;
    }

    public static Today getBeginAndEndByToDay(){
        LocalDateTime now = parse(LocalDateTime.now().toString());
        return new Today(beginOfDay(now),endOfDay(now));
    }


}
